package com.jiyun.wait.config;

import com.jiyun.wait.service.impl.WaitServiceImpl;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AcknowledgeMode;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

//监听队列消息并做出处理
@Component
@Slf4j
public class RabbitMqListener {
    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private WaitServiceImpl waitService;

    @RabbitListener(queues = "ReachTheDestination")
    public void messageListener(String message) {
        redisTemplate.delete("ReachTheDestination");
        log.info("司机到达乘客起点 message :{} " , message);
        redisTemplate.opsForValue().set("ReachTheDestination",message,30, TimeUnit.MINUTES);
    }
    @RabbitListener(queues = "DriverTakesOrders")
    public void messageListener2(String message) {
        log.info("已有司机接单 message :{} " , message);
        redisTemplate.opsForValue().set("DriverTakesOrders",message,30, TimeUnit.MINUTES);
    }
}
